
// BrowseHTMListView.cpp : implementation of the CBrowseHTMListView class
//

#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "BrowseHTMList.h"
#endif

#include "BrowseHTMListDoc.h"
#include "BrowseHTMListView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CBrowseHTMListView

IMPLEMENT_DYNCREATE(CBrowseHTMListView, CHtmlView)

BEGIN_MESSAGE_MAP(CBrowseHTMListView, CHtmlView)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
	ON_COMMAND(ID_FILE_OPEN, &CBrowseHTMListView::OnFileOpen)
	ON_COMMAND(ID_FONTSIZE_LARGEST, &CBrowseHTMListView::OnFontsizeLargest)
	ON_COMMAND(ID_FONTSIZE_LARGE, &CBrowseHTMListView::OnFontsizeLarge)
	ON_COMMAND(ID_FONTSIZE_MEDIUM, &CBrowseHTMListView::OnFontsizeMedium)
	ON_COMMAND(ID_FONTSIZE_SMALL, &CBrowseHTMListView::OnFontsizeSmall)
	ON_COMMAND(ID_FONTSIZE_SMALLEST, &CBrowseHTMListView::OnFontsizeSmallest)
END_MESSAGE_MAP()

// CBrowseHTMListView construction/destruction

CBrowseHTMListView::CBrowseHTMListView()
{
	// TODO: add construction code here

}

CBrowseHTMListView::~CBrowseHTMListView()
{
}

BOOL CBrowseHTMListView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CHtmlView::PreCreateWindow(cs);
}

void CBrowseHTMListView::OnInitialUpdate()
{
	CHtmlView::OnInitialUpdate();

	Navigate2(_T("http://illinois.edu/"),NULL,NULL);
}

void CBrowseHTMListView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CBrowseHTMListView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// CBrowseHTMListView diagnostics

#ifdef _DEBUG
void CBrowseHTMListView::AssertValid() const
{
	CHtmlView::AssertValid();
}

void CBrowseHTMListView::Dump(CDumpContext& dc) const
{
	CHtmlView::Dump(dc);
}

CBrowseHTMListDoc* CBrowseHTMListView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBrowseHTMListDoc)));
	return (CBrowseHTMListDoc*)m_pDocument;
}
#endif //_DEBUG


// CBrowseHTMListView message handlers


void CBrowseHTMListView::OnFileOpen()
{
	// TODO: Add your command handler code here
	CString str;
	str = "Text Files|*.txt||";

	CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, str);

	if(fileDlg.DoModal() == IDOK)
	{
		((CBrowseHTMListApp *)AfxGetApp())->m_strFolderPath = fileDlg.GetFolderPath();
		
		((CBrowseHTMListApp *)AfxGetApp())->LoadHTMList(fileDlg.GetPathName());
		((CBrowseHTMListApp *)AfxGetApp())->LoadHTMLItem();
	}

}


bool CBrowseHTMListView::LoadHTMLItem(CString path)
{
	Sleep(500);
	Navigate2(path, 0, NULL);
	return true;
}


void CBrowseHTMListView::OnFontsizeLargest()
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(4l);

	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);
}


void CBrowseHTMListView::OnFontsizeLarge()
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(3l);

	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);
}


void CBrowseHTMListView::OnFontsizeMedium()
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(2l);

	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);
}


void CBrowseHTMListView::OnFontsizeSmall()
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(1l);

	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);
}


void CBrowseHTMListView::OnFontsizeSmallest()
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(0l);

	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);
}




void CBrowseHTMListView::OnTitleChange(LPCTSTR lpszText)
{
	// TODO: Add your specialized code here and/or call the base class
	if (m_pDocument != NULL)
		m_pDocument->SetTitle(lpszText);

	CHtmlView::OnTitleChange(lpszText);
}
